﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Guru.Data;

public partial class FE_SelectRoomsModal : HSMPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.PageType = GuruPageType.Modal;
        this.FixedModalWidth = HSMConstants.DefaultFixedModalWidth;
        if (!IsPostBack)
            LoadRooms(); 
    }
    protected void uxChoose_Click(object sender, EventArgs e)
    {
        string ids = string.Empty;
        foreach (string id in uxDiagrams.SelectedRooms)
            ids += id + HSMConstants.Separator;
        string script = string.Format("parent.OnSelectedChanged('{0}');", ids.Trim(HSMConstants.Separator));
        this.CloseModal(2, script);
    }
    protected void LoadRooms()
    {
        GuruParameterCollection parameters = new GuruParameterCollection();
        parameters.AddUserLoggedParams();
        parameters.Add("@ViewDate", HSMSessionManager.HotelFilterOptions.ViewDate, DbType.Date);
        parameters.Add("@RoomStatus", HSMEnums.RoomStatus.Empty, DbType.Int32);
        DataTable rooms = HSMCommon.HSMBusiness.GetDataTable("spa_HSM_Room_GetFromDeskDiagram", parameters);
        
        if (IsSecureQueryString && SecureQueryString["rooms"].IsNotEmpty())
        {
            string selectedRooms = SecureQueryString["rooms"];
            selectedRooms = HSMConstants.Separator + selectedRooms + HSMConstants.Separator;
            for (int i = 0; i < rooms.Rows.Count; i++)
            {
                if (selectedRooms.Contains(HSMConstants.Separator + rooms.Rows[i]["RoomID"].ToString() + HSMConstants.Separator))
                    rooms.Rows[i]["IsSelected"] = 1;
            }
        }
        this.uxDiagrams.RoomList = rooms;
        this.uxDiagrams.DataBind();
    }
}
